home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / object / VIews.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-24  |  5.1 KB  |  282 lines

  1. /********************************************************************
  2.  * lindner
  3.  * 3.2
  4.  * 1993/03/24 17:09:01
  5.  * /home/mudhoney/GopherSrc/CVS/gopher+/object/VIews.c,v
  6.  * Exp
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992, 1993 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: VIews.c
  14.  * Various functions to handle gopher+ views
  15.  *********************************************************************
  16.  * Revision History:
  17.  * VIews.c,v
  18.  * Revision 3.2  1993/03/24  17:09:01  lindner
  19.  * Fixed a memory leak
  20.  *
  21.  * Revision 3.1.1.1  1993/02/11  18:03:01  lindner
  22.  * Gopher+1.2beta release
  23.  *
  24.  * Revision 2.1  1993/02/09  22:48:50  lindner
  25.  * Changes for multilingual views
  26.  *
  27.  * Revision 1.1  1993/01/31  00:31:12  lindner
  28.  * Initial revision
  29.  *
  30.  *
  31.  *********************************************************************/
  32.  
  33. #include "VIews.h"
  34. #include "Malloc.h"
  35. #include "String.h"
  36. #include "BLblock.h"
  37.  
  38.  
  39. static char *ANSILangs[] = {
  40.      "Da_DK", "Nl_BE", "Nl_NL", "En_GB", "En_US", "Fi_FI", "Fr_BE",
  41.      "Fr_CA", "Fr_CH", "Fr_FR", "De_CH", "De_DE", "El_GR", "Is_IS",
  42.      "It_IT", "Jp_JP", "No_NO", "Pt_PT", "Es_ES", "Sv_SE", "Tr_TR",
  43.      NULL
  44.      };
  45.  
  46. static char *ANSILangEn[] = {
  47.      "Danish",
  48.      "Dutch (Belgium)",
  49.      "Dutch",
  50.      "English (Great Britian)",
  51.      "English (USA)",
  52.      "Finnish",
  53.      "French (Belgium)",
  54.      "French (Canada)",
  55.      "French (Switzerland)",
  56.      "French",
  57.      "German (Switzerland)",
  58.      "German",
  59.      "Greek",
  60.      "Icelandic",
  61.      "Italian",
  62.      "Japanese",
  63.      "Norwegian",
  64.      "Portuguese",
  65.      "Spanish",
  66.      "Swedish",
  67.      "Turkish",
  68.      NULL
  69.      };
  70.  
  71.  
  72. char *
  73. VIprettyLang(vi, currentlang)
  74.   VIewobj *vi;
  75.   char    *currentlang;
  76. {
  77.      int i;
  78.  
  79.      for (i=0; ;i++) {
  80.       if (ANSILangs[i] == NULL)
  81.            return(NULL);
  82.  
  83.       if (*(VIgetLang(vi)) == *(ANSILangs[i])) {
  84.            if (strcmp(ANSILangs[i], VIgetLang(vi)) == 0)
  85.             return(ANSILangEn[i]);
  86.       }
  87.      }      
  88. }
  89.  
  90.  
  91.  
  92.  
  93. VIewobj *
  94. VInew()
  95. {
  96.      VIewobj *temp;
  97.  
  98.      temp = (VIewobj *) malloc(sizeof(VIewobj));
  99.  
  100.      temp->Type = STRnew();
  101.      temp->Lang = STRnew();
  102.      temp->Size = STRnew();
  103.      temp->comments = STRnew();
  104.      
  105.      VIinit(temp);
  106.      return(temp);
  107. }
  108.  
  109. /*** Initialize the VIewobj ***/
  110.  
  111. void
  112. VIinit(vi)
  113.   VIewobj *vi;
  114. {
  115.      STRinit(vi->Type);
  116.      STRinit(vi->Lang);
  117.      STRinit(vi->Size);
  118.      STRinit(vi->comments);
  119. }
  120.  
  121.  
  122. /** Destroy the VIewobj ***/
  123.  
  124. void
  125. VIdestroy(vi)
  126.   VIewobj *vi;
  127. {
  128.      STRdestroy(vi->Type);
  129.      STRdestroy(vi->Lang);
  130.      STRdestroy(vi->Size);
  131.      STRdestroy(vi->comments);
  132.  
  133.      free(vi);
  134. }
  135.  
  136.  
  137. /** copy a VIewobj **/
  138.  
  139. void
  140. VIcpy(videst, viorig)
  141.   VIewobj *videst, *viorig;
  142. {
  143.      STRcpy(videst->Type, viorig->Type);
  144.      STRcpy(videst->Lang, viorig->Lang);
  145.      STRcpy(videst->Size, viorig->Size);
  146.      STRcpy(videst->comments, viorig->comments);
  147. }
  148.  
  149.  
  150. /** Put a VIewobj in a line according to G+ protocol **/
  151.  
  152. void
  153. VItoLine(vi, tmpstr)
  154.   VIewobj *vi;
  155.   char *tmpstr;
  156. {
  157.      char *cp;
  158.      
  159.      tmpstr[0] = ' ';
  160.      tmpstr[1] = '\0';
  161.      
  162.      strcat(tmpstr, VIgetType(vi));
  163.  
  164.      cp = VIgetLang(vi);
  165.      if (cp != NULL) {
  166.       strcat(tmpstr, " ");
  167.       strcat(tmpstr, cp);
  168.      }
  169.  
  170.      /** Size **/
  171.      strcat(tmpstr, ": <");
  172.      strcat(tmpstr, VIgetSize(vi));
  173.      strcat(tmpstr, ">");
  174.  
  175.      /** Comments **/
  176.      cp = VIgetComments(vi);
  177.      if (cp != NULL) {
  178.       strcat(tmpstr, " ");
  179.       strcat(tmpstr, cp);
  180.      }
  181. }
  182.  
  183.  
  184. /** Siphon a G+ view line into a VIewobj **/
  185.  
  186. boolean
  187. VIfromLine(vi, line)
  188.   VIewobj *vi;
  189.   char *line;
  190. {
  191.      char tmpstr[256], *cp;
  192.      int i;
  193.  
  194.      /** Okay, read until the next space, put the result in tmpstr **/
  195.      for (cp = line,i=0; (*cp != ' '&&*cp!='\0'&&*cp!=':'); cp++,i++)
  196.       tmpstr[i] = *cp;
  197.      
  198.      tmpstr[i]='\0';
  199.      line = cp+1;
  200.      VIsetType(vi, tmpstr);
  201.  
  202.      if (*line == '\0')
  203.       return(FALSE);
  204.  
  205.  
  206.      /** Parse language **/
  207.      if (*line != ':') {
  208.       for (cp = line,i=0; (*cp != ' '&&*cp!='\0'&& *cp!=':'); cp++,i++)
  209.            tmpstr[i] = *cp;
  210.       tmpstr[i]='\0';
  211.       line = cp+1;
  212.       VIsetLang(vi, tmpstr);
  213.      }
  214.       
  215.      if (*line == '\0')
  216.       return(FALSE);
  217.      
  218.      /** Okay, parse off the size **/
  219.      while (*line != '<')
  220.       line ++;
  221.      
  222.      line++;
  223.  
  224.      for (cp = line,i=0; (*cp!='\0'&& *cp!='>'); cp++,i++)
  225.       tmpstr[i] = *cp;
  226.      tmpstr[i]='\0';
  227.      line = cp+1;
  228.      VIsetSize(vi, tmpstr);
  229.  
  230.      if (*line != '\0')
  231.       VIsetComments(vi, line);
  232.  
  233.      return(TRUE);
  234. }
  235.  
  236. char *
  237. VIgetViewnLang(vi, line)
  238.   VIewobj *vi;
  239.   char *line;
  240. {
  241.      if (VIgetType(vi) == NULL)
  242.       return("");
  243.      strcpy(line, VIgetType(vi));
  244.      strcat(line, " ");
  245.      if (VIgetLang(vi)!= NULL)
  246.       strcat(line, VIgetLang(vi));
  247.      return(line);
  248. }
  249.  
  250.  
  251. /*
  252.  * Generates a View Array from a Block
  253.  */
  254.  
  255. void
  256. VIAfromBL(via,bl)
  257.   VIewArray *via;
  258.   Blockobj *bl;
  259. {
  260.      int i;
  261.      char *cp;
  262.      VIewobj   *vi;
  263.  
  264.      if (strcasecmp(BLgetName(bl),"VIEWS")!=0)
  265.       return;
  266.  
  267.      vi  = VInew();
  268.      
  269.      for (i=0; i<BLgetNumLines(bl);i++) {
  270.       cp = BLgetLine(bl, i);
  271.       VIinit(vi);
  272.       
  273.       if (VIfromLine(vi, cp))
  274.            VIApush(via,vi);
  275.       else
  276.            ;
  277.      }
  278.      VIdestroy(vi);
  279. }
  280.   
  281.  
  282.